// Display random quotes from a file.
// Date 20:44 12/10/2016
// By Ben a.k.a DreamVB

#include <iostream>
#include <time.h>
#include <vector>

using namespace std;
using std::cout;
using std::endl;
using std::cin;

int main(int argc, char *argv[]){
	FILE *fp = NULL;
	vector<string>lines;
	char line[_MAX_PATH];
	int rnd = 0;
	int pos = 0;
	string sLine = "";
	string s0 = "";

	srand(time(0));

	//Open file
	fp = fopen("quotes.txt", "r");
	
	if (!fp){
		cout << "Cannot open quotes file" << endl;
		exit(1);
	}
	
	while (!feof(fp)){
		fgets(line, _MAX_PATH, fp);
		if (strlen(line) > 0){
			lines.push_back(line);
		}
	}
	//Close file
	fclose(fp);

	cout << "Quote ...." << endl << endl;
	//Pull out a random quote.
	rnd = rand() % lines.size();
	//Get random quote
	sLine = lines[rnd];
	pos = sLine.find_last_of('|');
	if (pos != string::npos){
		s0 = sLine.substr(pos + 1);
		cout << "   " << sLine.substr(0, pos).c_str() <<
			endl << "  --" << s0.c_str() << endl;
	}

	system("pause");
	return 0;
}